#include "router.h"

RouterManager::RouterManager(QStackedWidget *stackedWidget, QObject *parent) : QObject(parent), stackedWidget(stackedWidget) {}

void RouterManager::registerRouter(QString router_name, QWidget *widget) {
    if (!stacked_routers.contains(router_name)) {
        stacked_routers.insert(router_name, widget);
        stackedWidget->addWidget(widget);
    }
}

bool RouterManager::navigateTo(const QString &router_name, const QVariantMap &params) {
    if (stacked_routers.contains(router_name)) {
        stackedWidget->setCurrentWidget(stacked_routers[router_name]);
        emit routeChanged(router_name, params);
        return true;
    }
    return false;
}

